<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 基本数据类型
      console.log(typeof undefined === "undefined");
      console.log(typeof true === "boolean");
      console.log(typeof 42 === "number");
      console.log(typeof "ssss" === "string");
      console.log(typeof { name: "zs" } === "object");
      console.log(typeof Symbol() === "symbol");

      // 一个特殊的值 null
      console.log(typeof null === "object");
      // 判断null的方式
      let a = null;
      console.log(!a && typeof a === "object");
      console.log(Object.prototype.toString.call(a) === "[object Null]");

      // 特殊值function
      console.log(typeof function () {} === "function");
      console.dir(function () {});

      // typeof使用的场景是可以进行内置变量的安全防范
      // 比如我们要判断浏览器中的某些api是否支持 可以这样子
      if (typeof xxxApi === "undefined") {
        console.log("不存在");
      }
      if (!xxxApi) {
        console.log("会报错");
      }
    </script>
  </body>
</html>
